package com.io.buffered;

import java.io.*;

/**
 * 字符缓冲流+新增方法（不能发生多态）
 *
 * @author jiangbang
 * @date 2016/6/2
 */
public class BufferedCharDemo {

    /**
     * 文件拷贝
     */
    public static  void test3(){
        //1.建立联系 服了对象 目的地
        File file= new File("D:/demo/1.txt");
        File file2= new File("D:/demo/2.txt");
        //2.选择流
        BufferedWriter os = null;//文件输出流  Writer FileWriter
        BufferedReader is = null;//文件输入流  Reader FileReader
        try {
            //拷贝操作
            is = new BufferedReader(new FileReader(file));
            os = new BufferedWriter(new FileWriter(file2));
//            int len = 0;
//            char[] bytes = new char[100];
//            while(-1!=(len=is.read(bytes))){
//                os.write(bytes,0,len);
//            }
            String line = null;
            while(null!=(line=is.readLine())){
                os.write(line);
                os.newLine(); //换行
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                os.flush();
                os.close();
                is.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {
        test3();
    }
}
